using UnityEngine;
using UnityEngine.Networking;

public class TreasureBox : DamageManager
{
	public float DropRate = 1f;

	public ItemData[] Item;

	public Vector3 Offset = new Vector3(0f, 0.1f, 0f);

	public override void OnThisThingDead()
	{
		Spawn();
		base.OnThisThingDead();
	}

	private void Spawn()
	{
		if (base.isServer && (float)Random.Range(0, 100) >= 99f * (1f - DropRate) && Item.Length > 0)
		{
			ItemData itemData = Item[Random.Range(0, Item.Length)];
			Vector3 position = DetectGround(base.transform.position + Vector3.up);
			UnitZ.gameNetwork.RequestSpawnObject(itemData.gameObject, position, Quaternion.identity);
		}
	}

	private Vector3 DetectGround(Vector3 position)
	{
		if (Physics.Raycast(position, -Vector3.up, out RaycastHit hitInfo, 1000f))
		{
			return hitInfo.point + Offset;
		}
		return position;
	}

	private void UNetVersion()
	{
	}

	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		bool flag = base.OnSerialize(writer, forceAll);
		bool flag2 = default(bool);
		return flag2 | flag;
	}

	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
		base.OnDeserialize(reader, initialState);
	}
}
